package com.ruoyi.largeScreen.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.largeScreen.domain.ZjcEchartsStore;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.largeScreen.domain.ZjcEchartsChecked;
import com.ruoyi.largeScreen.service.IZjcEchartsCheckedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 控件显示库Controller
 * 
 * @author ruoyi
 * @date 2025-04-22
 */
@RestController
@RequestMapping("/largeScreen/checked")
public class ZjcEchartsCheckedController extends BaseController
{
    @Autowired
    private IZjcEchartsCheckedService zjcEchartsCheckedService;

    @PostMapping("/saveControls")
    public AjaxResult saveControls(@RequestBody String dataStr) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode rootNode = objectMapper.readTree(dataStr);
        JsonNode dataStrNode = rootNode.get("dataStr");
        String jsonData = dataStrNode.asText();
        JavaType listType = objectMapper.getTypeFactory().constructCollectionType(List.class, ZjcEchartsChecked.class);
        List<ZjcEchartsChecked> list = objectMapper.readValue(jsonData, listType);
        zjcEchartsCheckedService.saveControls(list);
        return success();
    }

    @GetMapping("/listAll")
    public AjaxResult listAll()
    {
        List<ZjcEchartsChecked> list = zjcEchartsCheckedService.selectZjcEchartsCheckedList(new ZjcEchartsChecked());
        return success(list);
    }
    /**
     * 查询控件显示库列表
     */
//    @PreAuthorize("@ss.hasPermi('largeScreen:checked:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZjcEchartsChecked zjcEchartsChecked)
    {
        startPage();
        List<ZjcEchartsChecked> list = zjcEchartsCheckedService.selectZjcEchartsCheckedList(zjcEchartsChecked);
        return getDataTable(list);
    }

    /**
     * 导出控件显示库列表
     */
    @PreAuthorize("@ss.hasPermi('largeScreen:checked:export')")
    @Log(title = "控件显示库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZjcEchartsChecked zjcEchartsChecked)
    {
        List<ZjcEchartsChecked> list = zjcEchartsCheckedService.selectZjcEchartsCheckedList(zjcEchartsChecked);
        ExcelUtil<ZjcEchartsChecked> util = new ExcelUtil<ZjcEchartsChecked>(ZjcEchartsChecked.class);
        util.exportExcel(response, list, "控件显示库数据");
    }

    /**
     * 获取控件显示库详细信息
     */
    @PreAuthorize("@ss.hasPermi('largeScreen:checked:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zjcEchartsCheckedService.selectZjcEchartsCheckedById(id));
    }

    /**
     * 新增控件显示库
     */
    @PreAuthorize("@ss.hasPermi('largeScreen:checked:add')")
    @Log(title = "控件显示库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZjcEchartsChecked zjcEchartsChecked)
    {
        return toAjax(zjcEchartsCheckedService.insertZjcEchartsChecked(zjcEchartsChecked));
    }

    /**
     * 修改控件显示库
     */
    @PreAuthorize("@ss.hasPermi('largeScreen:checked:edit')")
    @Log(title = "控件显示库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZjcEchartsChecked zjcEchartsChecked)
    {
        return toAjax(zjcEchartsCheckedService.updateZjcEchartsChecked(zjcEchartsChecked));
    }

    /**
     * 删除控件显示库
     */
    @PreAuthorize("@ss.hasPermi('largeScreen:checked:remove')")
    @Log(title = "控件显示库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zjcEchartsCheckedService.deleteZjcEchartsCheckedByIds(ids));
    }
}
